package com.kinon.market.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kinon.market.R;
import com.kinon.market.entity.DingdanEntity;
import com.kinon.market.sqlbean.UserBuyBean;

import java.util.ArrayList;

/**
 * 订单item
 */

public class DingdanAdapter extends BaseAdapter {
    Context context;
    ArrayList<DingdanEntity> dingdanList;
    int type = -1;
    private ArrayList<UserBuyBean> buyList;

    public DingdanAdapter(Context context, ArrayList<DingdanEntity> dingdanList) {
        super();
        this.context = context;
        this.dingdanList = dingdanList;
    }

    public DingdanAdapter(Context context, ArrayList<UserBuyBean> buyList, int type) {
        super();
        this.context = context;
        this.buyList = buyList;
        this.type = type;
    }

    @Override
    public int getCount() {
        if (type != 0) {
            return dingdanList.size();
        } else {
            return buyList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (type != 0) {
            return dingdanList.get(position);
        } else {
            return buyList.get(position);
        }

    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHandle handle;
        if (view == null) {
            handle = new ViewHandle();
            view = LayoutInflater.from(context).inflate(R.layout.item_dingdan, null);
            handle.tv_bianhao = (TextView) view.findViewById(R.id.tv_bianhao);
            handle.tv_time = (TextView) view.findViewById(R.id.tv_shijian);
            view.setTag(handle);
        } else {
            handle = (ViewHandle) view.getTag();
        }
        if (type != 0) {
            handle.tv_bianhao.setText(dingdanList.get(position).getOrderno());
            handle.tv_time.setText(dingdanList.get(position).getTime());
        } else {
            handle.tv_bianhao.setText(buyList.get(position).getOrderno());
            handle.tv_time.setText(buyList.get(position).getTime());
        }

        return view;
    }

    class ViewHandle {
        /**
         * 订单编号
         */
        TextView tv_bianhao;
        /**
         * 姓名
         */
        TextView tv_time;
    }


}
